package org.zcl.config;

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zcl.inteceptor.WebServiceAuthInterceptor;
import org.zcl.service.UserInfoService;

import javax.xml.ws.Endpoint;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/8/9 11:43
 */
@Configuration
public class WebServiceConfig {

    @Autowired
    private Bus bus;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private WebServiceAuthInterceptor interceptor;

    /**
     * 设置WebService访问父路径
     * @return
     */
    @Bean
    public ServletRegistrationBean getRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), "/services/*");
    }

    @Bean
    public Endpoint messageEndPoint() {
        EndpointImpl endpoint = new EndpointImpl(this.bus, this.userInfoService);
        endpoint.publish("/userInfoService");
        endpoint.getInInterceptors().add(this.interceptor);
        return endpoint;
    }

}
